//获取昨天
function getYesterday() {
  var day1 = new Date();
  day1.setTime(day1.getTime() - 24 * 60 * 60 * 1000);
  var s1 = day1.getFullYear() + '-' + (day1.getMonth() + 1) + '-' + day1.getDate();
  return s1;
}

//获取前天天
function beforeYesterday() {
  var day1 = new Date();
  day1.setTime(day1.getTime() - 24 * 60 * 60 * 1000 * 2);
  var s1 = day1.getFullYear() + '-' + (day1.getMonth() + 1) + '-' + day1.getDate();
  return s1;
}
//日期获取毫秒数
function getSeconds(date) {
  var time = new Date(date.replace(/-/g, '/'));
  var seconds = time.getTime();
  return seconds;
}
//时间转换

export const timeFormat = function (time) {
  
  //时间转换
  var strtime = time;
  var result;
  var newDate = new Date();
  var date = getSeconds(strtime);
  const sub = Date.now() - date;
  const yesterday = 1000 * 60 * 60 * 48;
  const yesterdayStart = getSeconds(getYesterday() + ' ' + '00:00:00'); //昨天开始时间
  const yesterdayEnd = getSeconds(getYesterday() + ' ' + '23:59:59'); //昨天结束时间
  const beforeyesterdayStart = getSeconds(beforeYesterday() + ' ' + '00:00:00'); //前天开始时间
  const beforeyesterdayEnd = getSeconds(beforeYesterday() + ' ' + '23:59:59'); //前天结束时间
  const thisYear = getSeconds(newDate.getFullYear() + '-01-01' + ' ' + '00:00:00'); //今年开始时间
  if (date > yesterdayEnd) {
    result = '今天' + strtime.substr(10, 6);
  } else if (date >= yesterdayStart && date <= yesterdayEnd) {
    result = '昨天' + strtime.substr(10, 6);
  } else if (date >= beforeyesterdayStart && date <= beforeyesterdayEnd) {
    result = '前天' + strtime.substr(10, 6);
  } else {
    result = strtime.substr(0, 16);
  }
  return result;
};


